export default {
  methods: {
    /**
     * 初始化操作
     */
    initMethod() {
      this.stepOneData.supplierId = this.$route.query.id || ''; // 供应商id
      this.isAccountSettle = !!this.$route.query.isAccountSettle; // 是否待办详情账号结算
      /** 成本管理列表跳转传值 */
      this.initFromCost();
      // 从哪里发起结算, saleSupplier:销售供应商列表  mengliSupplier:萌力供应商列表
      this.initCostBelong();
      this.initData();
    },
    // 成本管理列表跳转传值
    initFromCost() {
      const costItemId = Number(this.$route.query.costItemId) || null; // 成本项ID
      const costItemName = this.$route.query.name || null; // 成本项名称
      if (costItemId) {
        this.process = 1;
        this.$set(this.stepOneData, 'selectCost', [{ id: costItemId, name: costItemName }]);
      }
    },
    initCostBelong() {
      // 从哪里发起结算, saleSupplier:销售供应商列表  mengliSupplier:萌力供应商列表
      const pageFrom = this.$route.query.from || 'saleSupplier';
      if (pageFrom === 'saleSupplier') this.stepOneData.costBelong = 0;
      if (pageFrom === 'mengliSupplier') this.stepOneData.costBelong = 2;
      if (pageFrom === 'commerceSupplier') this.stepOneData.costBelong = 6;
      this.stepOneData.pageFrom = pageFrom;
      // 填入成本来源
      if (this.$route.query.costBelong || this.$route.query.costBelong === 0) {
        this.stepOneData.costBelong = Number(this.$route.query.costBelong); // 成本来源
      }
    },
    initData() {
      if (this.isAccountSettle) {
        let data = localStorage.getItem('accountSettleData');
        if (data && !['null', 'undefined'].includes(data)) {
          data = JSON.parse(data);
          this.settleId = data.id;
          this.getDetail();
        }
        // 待办，账号结算
        // this.firstOpenDialog = 'firstOpenDialog';
        this.setStepId({ process: 2 });
      } else {
        // 非订单请款
        this.isNotOrder = !!this.$route.query.isNotOrder; // 非订单请款
        if (this.isNotOrder) {
          // this.firstOpenDialog = 'firstOpenDialog';
          this.setStepId({ process: 2 });
          if (this.settleId) {
            this.getDetail();
          }
        }
      }
    }
  }
};
